<?php
/**
 * db.f.class.php 数据库工厂类
 *
 * 统一规范数据库共享方法 
 *
 * @author          hyperblue
 * @version         0.1
 * @copyright       (C) 2011- *
 * @license	        http://www.bingceng.com
 * @lastmodify	    2011-08-10 14:44
 */
 
defined('BC_INC_PATH') or exit("Access Denied!");

class Fdb {

	static private $_error = NULL;
	
	static private $_config = array(
		'db_host' => null,
		'db_name' => null,
		'db_user' => null,
		'db_password' => null,
		'db_port' => '3306',
		'db_charset' => 'utf8',
		'db_prefix' => '',
		'db_type' => 'mysql'
	);
	
	static private $_adapter = NULL;
	
	/**
	 * 构造函数
	 * @param $config array
	 */
	public function __construct($config) {
		//self::getConfig($config);
		//self::factory();
		//self::error();
	}
	
	/**
	 * 获取数据库配置
	 *
	 * @param $config array
	 * @return void
	 */
	static public function getConfig($config) {
		self::$_config = $config;
	}
	
	/**
	 * 数据库工厂
	 *
	 * 根据数据库类型实例化对应数据库，赋值给类的静态成员变量
	 */
	static function factory() {
		$dbType = self::$_config['db_type'];
		if (!self::$_adapter) {
			switch ($dbType) {
				case 'mysql':
					self::$_adapter = new db_mysql(self::$_config);
					break;
				case 'oracle':
					self::$_adapter = new db_oracle(self::$_config);
					break;
				case 'pqsql':
					self::$_adapter = new db_pqsql(self::$_config);
					break;
				case 'sqlserver':
					self::$_adapter = new db_sqlServer(self::$_config);
					break;
				case 'access':
					self::$_adapter = new db_access(self::$_config);
					break;
				default:
					self::$_error = 'Please set a database type!';
					break;
			}
		}
		
		return self::$_adapter;
	}
	
	/**
	 * 错误提示
	 */
	static public function error() {
		if (self::$_error) {
			die(self::$_error);
			exit();
		}
	}
}

?>
